package com.flyme.module.base.provider.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.flyme.common.core.model.ResultBody;
import com.flyme.common.core.model.query.CriteriaQuery;
import com.flyme.common.core.model.query.PagerInfo;
import com.flyme.common.core.model.query.PqGrid;
import com.flyme.core.base.supper.controller.BaseController;
import com.flyme.core.base.supper.entity.EntityMap;
import com.flyme.module.base.client.api.SysMessageSendRemoteService;
import com.flyme.module.base.client.entity.SysMessage;
import com.flyme.module.base.client.entity.SysMessageSend;
import com.flyme.module.base.provider.service.SysMessageSendService;
import com.flyme.module.base.provider.service.SysMessageService;
import com.flyme.module.base.provider.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;


/**
 * @author flyme
 */
@Slf4j
@RestController
@Api(description = "消息发送管理接口")
@RequestMapping("/messagesend")
@Transactional
public class SysMessageSendController extends BaseController<SysMessageSendService, SysMessageSend> implements SysMessageSendRemoteService {

    @Autowired
    private SysUserService userService;

    @Autowired
    private SysMessageService messageService;


    @PostMapping(value = "/list")
    @ApiOperation(value = "多条件分页获取")
    @Override
    public ResultBody list(@ModelAttribute PagerInfo pagerInfo, @ModelAttribute SysMessage message) {
        CriteriaQuery cq = new CriteriaQuery<EntityMap>(pagerInfo);
        cq.select("ms.id", "message.messageTitle","user.userName","ms.messageStatus","ms.createTime", "ms.updateTime",  "message.messageType", "message.messageContent");
        cq.createAlias("message","message");
        cq.createAlias("user","user");
        PqGrid pqGrid = bizService.pageList(cq);
        return ResultBody.success(pqGrid);
    }
    @PostMapping(value = "/delByIds/{ids}")
    @ApiOperation(value = "删除消息发送记录")
    @Override
    public ResultBody delByIds(@PathVariable Long[] ids) {
        bizService.removeByIds(CollectionUtil.toList(ids));
        return ResultBody.ok("删除成功");
    }
}

